package com.itheima.service.impl;

import com.itheima.mapper.EmpMapper;
import com.itheima.pojo.JobCountData;
import com.itheima.pojo.JobOption;
import com.itheima.service.ReportService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@Service
public class ReportServiceImpl implements ReportService {
    @Autowired
    private EmpMapper empMapper;

    @Override
    public JobOption empJobData() {
        // 创建JobOption对象用于封装职位统计信息
        JobOption jobOption = new JobOption();
        // 调用mapper查询各职位的员工数量数据
        List<JobCountData> jobCountDataList = empMapper.countEmpJobData();
        // 提取职位名称列表
        List<String> jobList = new ArrayList<>();
        for (JobCountData jobCountData : jobCountDataList) {
            jobList.add(jobCountData.getJobName());
        }
        jobOption.setJobList(jobList);
        // 提取各职位员工数量列表
        List<Integer> dataList = new ArrayList<>();
        for (JobCountData jobCountData : jobCountDataList) {
            dataList.add(jobCountData.getNum());
        }
        jobOption.setDataList(dataList);
        // 返回封装好的职位统计数据
        return jobOption;
    }

    @Override
    public List<Map<String, Object>> empGenderData() {
    return empMapper.empGenderData();
    }
}
